﻿using CommonUtils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Test.Core
{
    class 类型变更
    {
        static void sql(StringBuilder sb, string entity, string cTable, string uTable, string key)
        {
            if (entity.Contains("private String " + key + ";"))
                sb.AppendLine("ALTER TABLE /*{}*/ \t\"{}\" \tMODIFY \"{}\" VARCHAR(50);", cTable, uTable, StringUtil.CamelToUnderLine(key));
        }

        public static void run(string[] args)
        {
            try
            {
                var folders = new List<DirectoryInfo>();
                var folder = FolderUtil.Get("D:\\Subversion\\ygcg-dev\\jeecg-boot\\jeecg-boot\\jeecg-boot-module-system-ygcg" +
                    "\\src\\main\\java\\org\\jeecg\\modules");
                folders.AddRange(folder.GetFolders());
                folder = FolderUtil.Get("D:\\Subversion\\ygcg-dev\\jeecg-boot\\jeecg-boot\\jeecg-boot-module-system" +
                    "\\src\\main\\java\\org\\jeecg\\modules");
                folders.AddRange(folder.GetFolders());
                var sb = new StringBuilder();
                foreach (var subFolder in folders)
                {
                    var entityFolder = subFolder.GetChildFolder("entity");
                    if (!entityFolder.Exists)
                        continue;
                    foreach (var entity in entityFolder.GetFiles())
                    {
                        var entityCode = entity.GetText();
                        var cTable = entity.Name.Replace(".java", "");
                        var uTable = StringUtil.CamelToUnderLine(cTable);
                        sql(sb, entityCode, cTable, uTable, "num");
                        sql(sb, entityCode, cTable, uTable, "cadreNum");
                        sql(sb, entityCode, cTable, uTable, "planNum");
                        sql(sb, entityCode, cTable, uTable, "reportNum");
                        sql(sb, entityCode, cTable, uTable, "fileListNum");
                        sql(sb, entityCode, cTable, uTable, "listNum");
                        sql(sb, entityCode, cTable, uTable, "instructionNum");
                        sql(sb, entityCode, cTable, uTable, "fileNum");
                        sql(sb, entityCode, cTable, uTable, "similarTeamId");
                    }
                }
                sb.Print();
            }
            catch (Exception ex)
            {
                LogUtil.log(ex);
            }
        }
    }
}
